#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string>
#include<vector>
#include<unordered_map>
#include <iostream>

using namespace std;

    int minNumberOfFrogs(string croakOfFrogs)
    {
        string s = "croak";
        int n = s.size() ;
        vector<int> hash(n);
        unordered_map<char, int> index;

        for (int i = 0; i < n; i++) index[s[i]] = i;

        for (auto ch : croakOfFrogs)
        {
            if (ch == s[0])
            {
                if (hash[n - 1] != 0)hash[n - 1]--;
                hash[0]++;
            }
            else
            {
                int i = index[ch];
                if (hash[i - 1] == 0)return -1;
                hash[i - 1]--;
                hash[i]++;
            }
        }

        for (int i = 0; i < n - 1; i++)
        {
            if (hash[i] != 0)return -1;
        }
        return hash[n - 1];
    }


    int main()
    {
        string s = "croak";
        int n=minNumberOfFrogs("croakcroak");
        cout << n << endl;
    }